import requests,json
from pymongo import MongoClient
import base64
import YITUYDN


def get_ovo_sim(a_base64, b_base64):
    url = 'http://192.168.1.40:5000/faceoobig'
    data = {
        "a": a_base64,
        "b": b_base64
    }
    try:
        r = requests.post(url, json.dumps(data))
        # print(r.text)

        res = json.loads(r.text)
        return res['s']
    except:
        return -1


# url = 'http://192.168.1.40:5000/faceoobig'
# data = {
# 	"a":"/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCACJAIkDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD7KoopDwM0AVdVvbWwsJr28lWK3hRnkc9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/jXqUqd6SZ59SXLUaMaAncCPSvoT9kmQjxijbgAyOh98qT/AENfO1vIAQScZ7V7f+yvemHxxbxZyJGG0+h3DP8A46WqJKxcHeLPs1emfUZp1NXv+n5U6mjJBUV0VFvIWOAEYnn2qWq2o/8AHnJ/un+RqWI+CfjZF/xcW9igDSNMYmVU5LFokP8AWtL4U/DDUL/Ul1HXrGW2toSGigmUqzt6kH0/XNdPb/8AJy9x/uRf+i1r162/4+rr/rpXoYemmrkVJPYn8PaVDA6BY1AxjpiuL1bR/wCyPFl0FTEU8vnJxwN3JH5k16VpvQVzHxG/5Clt9D/Slj4KUNSsLK0ivbxLJH92lNmoOSuKXTPuVel+6K8OSPUi7FVYQV24p0duA3Sp46ev3qlIbYw4RTWXfSsQVz14rSuO9ZVx978f8adiUO+HunJJ4jvL1hl1jEQOOgJyf5Ctrxb4W07XtOuLC9t1lgnUhgR056j0PcH/ABqL4ef8f17/AL39K6h69zBq1JI8vEyvUZ8Z+NPhp4m8MXl066dd32nRsXS6hBf5P7zqPun1z6Vp/AbVGsfiJooBz51yq56cHNfUN3/x+r/uP/KvlrwD/wAlsX/sLf1oq0opXCE2kffyEMMggj2NOqlov/INg/65j+tXa4mVuf/ZcMlB8MroM4BeBEpEG6CghQ=="
# }
# r = requests.post(url, json.dumps(data))
# print(r)
# print(r.text)
# print(type(r.text))

conn_ = MongoClient('192.168.1.12', 27017)
# 获取所有数据库名字

record_ = conn_.guidang4.record
ovodata_ = conn_.guidang4.ovodata
capture_ = conn_.guidang4.capture

allimg = record_.find({})
fp_ip = '192.168.1.160'
fp_port = 11180
username = 'admin3'
password = 'admin12345678'
yituydn = YITUYDN.YITUYDN(fp_ip, fp_port, username, password)
# face_yitu_171_feature_base64 = "FZ6U/dEa0/mNlg70RBJN/weOhe3ACsHpf476Fj0cwfAJjIXGSQOc1Yd87zje8ik75G+e1a4RTiNHg9bMHuc5OMS8tL2b0LVDT7swSv7z80PDV1qPhjuDqzS4VafzzOinSsw1jI+hcp4szK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x3SHGYKMmtlO1/6ZChTiWMZpthiB6vnYTdC9mAkVwVfFLPUXgIXY10ynDJcIGGBWxFZUFo/6Z9ZLxTuWBwVPVcMfIxWO8KbVSu2KlQZEnlTCckIUjYUl1EmxmZQFbB1TwTVBE4yL9NNIjIiTBFYcUsA3kBKLoCPSR5EnkgN6W1HPCE8RioCy0Ub05pECDkpQzmjOEInq0dBF14WQAV3Z382xrR+I+eDf1LEknwD46P7MMKauB/iv3kOxY5"
#
# ovo_rtn = yituydn.ovo(face_yitu_171_feature_base64, hit_image_yitu_171_feature_base64)
# print(ovo_rtn)

def get_url(uri):
    arr = uri.split('@')
    uri = arr[0] + '@' + arr[1]
    cluster_id = arr[2]
    return 'http://' + fp_ip + ':' + str(fp_port) + '/storage/v1/image/global?cluster_id=' + cluster_id + '&uri_base64=' + tobase64(uri)


def tobase64(str):
    encodestr = base64.b64encode(str.encode('utf-8'))
    return encodestr.decode()

def get_img_base64(url):
    response = requests.get(url)
    img = response.content
    base64_data = base64.b64encode(img)
    s = base64_data.decode()
    return s
all_img_list = []
for imgg in allimg:
    all_img_list.append(imgg)

print(len(all_img_list))

count = 0
for img in all_img_list:
    count += 1
    print(count)
    if count <= 1764:
        continue

    if len(img['result']) > 0:
        aaa_id = img['face_image_id']
        aaa_img = capture_.find_one({'_id': aaa_id})
        aaa_url = get_url(aaa_img['face_image_uri'])
        aaa_feature_base64 = aaa_img['yitu_171_feature_base64']
        # print(aaa_feature_base64)
        aaa_base64 = get_img_base64(aaa_url)
        for hit_face_img in img['result']:
            bbb_id = hit_face_img['hit_face_image_id']
            idname1 = '%s_%s' % (aaa_id, bbb_id)
            idname2 = '%s_%s' % (bbb_id, aaa_id)
            img1 = ovodata_.find_one({'_id': idname1})
            img2 = ovodata_.find_one({'_id': idname2})
            if img1:
                continue
            if img2:
                continue

            bbb_img = capture_.find_one({'_id': bbb_id})
            bbb_url = get_url(bbb_img['face_image_uri'])
            bbb_feature_base64 = bbb_img['yitu_171_feature_base64']
            # print(bbb_feature_base64)
            bbb_base64 = get_img_base64(bbb_url)
            ovn_similarity = hit_face_img['similarity']
            ovo_similarity = get_ovo_sim(aaa_base64, bbb_base64)

            ovo_rtn = yituydn.ovo(aaa_feature_base64, bbb_feature_base64)
            # print(ovo_rtn)
            if ovo_rtn['rtn'] == 0:
                new_similarity = ovo_rtn['similarity']
            else:
                new_similarity = -1


            data = {
                '_id': '%s_%s' % (aaa_id, bbb_id),
                'a_url': aaa_url,
                'b_url': bbb_url,
                'ovn': ovn_similarity,
                'ovo': ovo_similarity,
                'yituovo': new_similarity
            }
            print(data)
            ovodata_.insert_one(data)